<template>
  <van-nav-bar title="个人信息" left-arrow @click-left="onClickLeft" />
  <div class="box">
    <div class="imgbox">
      <van-uploader
        v-model="fileList"
        multiple
        accept="file"
        max-count="1"
        :after-read="afterRead"
        @click="fn"
      />
      <img src="..\assets\image\touxiangzucejiaobiao.png" alt="" />
    </div>
  </div>
  <van-cell-group inset>
    <van-cell title="英文名" :value="myInfo.username || '点击添加'" is-link to="/reg" />
    <van-cell title="中文名" :value="myInfo.cusername || '点击添加'" is-link to="/reg" />
    <van-cell title="生日" :value="myInfo.birthday || '点击添加'" is-link to="/reg" />
    <van-cell title="性别" :value="myInfo.sex || '点击添加'" is-link to="/reg" />
  </van-cell-group>
  <van-button type="primary" to="/home/mine">保存</van-button>
</template>

<script>
import { ref } from "vue";
import { getMyInfoApi } from "../utils/api";
import { useRouter } from "vue-router";
export default {
  setup() {
    const router = useRouter();
    const onClickLeft = () => router.push("/home/mine");
    const img = require("../assets/image/reg2-photo.png");

    const fileList = ref([{ url: img }]);
    const afterRead = file => {
      // 此时可以自行将文件上传至服务器
      let formData = new FormData();
      formData.append("imgFile", file.file);
      let headerImg = file.content;
      console.log(headerImg);
    };
    const myInfo = ref({});
    const token = localStorage.getItem("token");
    getMyInfoApi({ token }).then(res => {
      if (res.status === 0) {
        myInfo.value = res.results;
      }
    });

    return {
      onClickLeft,
      afterRead,
      fileList,
      myInfo,
    };
  },
  methods: {
    fn() {},
  },
};
</script>

<style lang="less" scoped>
.box {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 100px;
  margin-bottom: 12.5px;
  .imgbox {
    position: relative;
    img {
      position: absolute;
      bottom: 7px;
      right: 7px;
      width: 23px;
      height: 23px;
    }
  }
}
.van-button {
  width: 300px;
  height: 45px;
  margin: 21px 38px;
  border-radius: 25px;
}
/deep/.van-uploader__upload {
  border-radius: 50%;
}
/deep/.van-uploader__preview-image {
  border-radius: 50%;
}
/deep/.van-cell::after {
  border-bottom: 0px;
}
</style>
